<template>
  <!-- 新增 搜索 -->
  <div>
    <!-- 表单 -->
    <FormPanel ref="form" :cols="3" :list="list" :isSubmitBtn="false" @formChange="formChange"></FormPanel>
    <el-row class="btn-group">
      <el-button type="primary" @click="FormPanelSeacher">搜 索</el-button>
      <el-button @click="FormPanelreset">重置</el-button>
    </el-row>
    <!-- 表格 -->
    <FilterTable
      ref="table"
      :columns="columns"
      columnsRef="partPartInventoryPartInventoryComponentsWenhua"
      :fetchapi="fetchApi"
      :params="fetchParams"
      height="200"
      selectionType="single"
      :datakey="'rows'"
      :onColumnsChange="columns => (this.columns = columns)"
      :onRowSelectChange="arr => (this.onChangeColumn = arr)"
      :onPageChange="onPageChange"
      :onEnterEvent="onEnterEvent"
    ></FilterTable>
    <el-row class="btn-group">
      <el-button type="primary" @click="confirmBtnClick">确 定</el-button>
      <el-button @click="$emit('cancel')">取 消</el-button>
    </el-row>
  </div>
</template>

<script>
import { state, mutations } from './../store';
import { queryPartInfo, queryPartStock } from '@/api/part/partOutbound/repairMaterials/index.js';
import { queryThreeTypeOrderDetail, partgetfourData } from '@/api/part/partInventory/partInventory/index.js';
export default {
  name: 'wenhua',
  props: ['orderType', 'orderNo'],
  data() {
    return {
      onChangeColumn: [],
      list: this.createList(),
      columns: this.createColumns(),
      fetchApi: partgetfourData,
      fetchParams: {
        orderNo: this.orderNo,
        orderType: this.orderType,
        xhrAbort: false
      }
    };
  },
  mounted() {
    this.list.find(x => x.fieldName === 'orderNo').initialValue = this.orderNo;
  },
  methods: {
    createList() {
      return [
        {
          type: 'INPUT',
          label: '文化公司',
          fieldName: 'orderNo'
        }
      ];
    },
    createColumns() {
      return [
        {
          title: '序号',
          // sorter: true,
          width: 50,
          dataIndex: 'xuhao',
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '文化公司',
          // sorter: true,
          dataIndex: 'mei1'
        },
        {
          title: '订单状态',
          // sorter: true,
          dataIndex: 'mei2'
        },
        {
          title: '供应商代码',
          // sorter: true,
          dataIndex: 'mei3'
        },
        {
          title: '供应商名称',
          // sorter: true,
          dataIndex: 'mei4'
        }
      ];
    },
    // 重置
    FormPanelreset() {
      this.$refs.form.RESET_FORM();
    },
    // 搜索
    FormPanelSeacher() {
      this.$refs.form.SUBMIT_FORM();
    },
    // 获取表单数据
    async partgetfourData() {
      let params = {};
      params.orderType = this.orderType;
      params.orderNo = '';
      const res = await partgetfourData(params);
    },
    formChange(val) {
      this.fetchParams = Object.assign({}, this.fetchParams, val, { xhrAbort: false });
    },
    onPageChange() {
      console.log('onPageChange');
    },
    async onEnterEvent(row) {
      // 双击选中  整合配件信息
      console.log('onEnterEvent', row);
      this.$emit('dblclickPartInfo', Object.assign({}, row));
      return;
      const res = await queryPartStock({
        partNo: row['PART_NO'],
        storageCode: row['STORAGE_CODE']
      });
      if (res.resultCode != 200) {
        console.log('查询配件 失败', res);
        return;
      }
      console.log('查询配件 成功', res);
      const part = res.data.rows[0];
      // 整合配件信息
      // const partInfo = Object.assign({}, row, part);
      const partInfo = Object.assign({}, part);
      console.log('整合后的配件信息', partInfo);
      this.$parent.setPartInfo(partInfo);
    },
    // 确定
    confirmBtnClick() {
      this.$emit('confirm', this.onChangeColumn);
    }
  }
};
</script>

<style scoped lang="less">
.btn-group {
  text-align: center;
  margin-top: 20px;
}
</style>
